/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.soa.controller.rsgl;

import com.lianzt.commondata.AbstractCommonData;
import com.soa.controller.SystemController;
import java.io.PrintWriter;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tomcat.util.http.fileupload.FileItem;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 *
 * @author lianzt
 */
@Controller
public class ZkfController {

    private static final Logger log = LoggerFactory.getLogger(ZkfController.class);
    @Resource
    private SystemController systemController;

    @RequestMapping("/upload")
    public void updateAj(HttpServletRequest request,HttpServletResponse response, PrintWriter out) {
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        try {
        AbstractCommonData in = (AbstractCommonData) request.getAttribute("page_data");
        in.getDataValue("head").putStringValue("service_code", "P12006");
        String dispoString = request.getHeader("Content-Disposition");
        int iFindStart = dispoString.indexOf("name=\"") + 6;
        int iFindEnd = dispoString.indexOf("\"", iFindStart);
        iFindStart = dispoString.indexOf("filename=\"") + 10;
        iFindEnd = dispoString.indexOf("\"", iFindStart);
        String sFileName = dispoString.substring(iFindStart, iFindEnd);
        log.debug("==================sFileName====" + sFileName);
        int i = request.getContentLength();
         byte buffer[] = new byte[i];
                int j = 0;
                while(j < i) { //获取表单的上传文件
                    int k = request.getInputStream().read(buffer, j, i-j);
                    j += k;
                }
        in.putStringValue("sxbh", request.getParameter("sxbh"));
        in.putObjectValue("filedata", buffer);
        in.putStringValue("filedata_name", sFileName);
        systemController.ajaxServicePost(request, out);
        } catch (Exception e) {

        }
    }
}
